package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

@EViewGroup(R.layout.item_po_wo_dictionary)
public class PoWoDictionaryItemView extends LinearLayout {
    @ViewById
    TextView itemPoWoDictionaryTitleText, itemPoWoDictionaryContentText;
    @ViewById
    ImageView itemPoWoDictionaryImage;


    public PoWoDictionaryItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PoWoDictionaryItemView(Context context) {
        super(context);
    }

    @Click(R.id.itemRootView)
    public void enterNewsDetail() {
        Intent intent = new Intent();
        intent.setClassName(getContext(),
                Constants.NEWSDETAILACTIVITY_CLASS_NAME);
        intent.putExtra("title", "宝沃词典");
        getContext().startActivity(intent);
    }

    /**
     * 加载数据
     *
     * @param itemJsonObject
     * @param position
     */
    public void loadData(JSONObject itemJsonObject, int position,
                         BitmapLoader bitmapLoader) {
        itemPoWoDictionaryTitleText.setText(TypeUtils.getJsonString(
                itemJsonObject, "subject"));
        itemPoWoDictionaryContentText.setText(TypeUtils.getJsonString(
                itemJsonObject, "desc"));
//		bitmapLoader.displayImage(
//				TypeUtils.getJsonString(itemJsonObject, "image"),
//				itemPoWoDictionaryImage);

        if (position % 3 == 0) {
            itemPoWoDictionaryImage.setImageResource(R.drawable.dictionary_img1);
        } else if (position % 3 == 1) {
            itemPoWoDictionaryImage.setImageResource(R.drawable.dictionary_img2);
        } else if (position % 3 == 2) {
            itemPoWoDictionaryImage.setImageResource(R.drawable.dictionary_img3);
        }

    }

}
